package com.sky.service.impl;

import com.sky.constant.MessageConstant;
import com.sky.result.Result;
import com.sky.service.ShopService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class ShopServiceImpl implements ShopService {
	
	private final StringRedisTemplate redisTemplate;
	
	public ShopServiceImpl(StringRedisTemplate redisTemplate) {this.redisTemplate = redisTemplate;}
	
	@Override
	public Result<Integer> getShopStatus() {
		String shopStatus = redisTemplate.opsForValue().get("status");
		if (shopStatus != null) {
			return Result.success(Integer.parseInt(shopStatus));
		} else {
			return Result.error(MessageConstant.UNKNOWN_ERROR);
		}
	}
	
	@Override
	public Result setShopStatus(Integer status) {
		redisTemplate.opsForValue().set("status", String.valueOf(status));
		return Result.success();
	}
}
